package dao

import (
	SQL "database/sql"
	"time"
	"webProject/sql"
)

type Order struct {
	orderNum  int
	orderDate time.Time
	custId    int
}

func SelectOrder(id ...interface{}) []Order {
	connection := sql.CreateConnection("root", "admin", "mysqllearn")
	var rows *SQL.Rows
	var e error
	if id != nil {
		num := len(id)
		placeholders := sql.Placeholders(num)
		rowsql := `SELECT * FROM orders where order_num in (` + placeholders + `)`
		rows, e = sql.Select(connection, rowsql, id...)
	} else {
		rows, e = sql.Select(connection, `SELECT * FROM orders`)
	}
	if e != nil {
		panic(e)
	}
	var orders []Order
	for rows.Next() {
		var order Order
		_ = rows.Scan(&order.orderNum, &order.orderDate, &order.custId)
		orders = append(orders, order)
	}
	return orders
}

func UpdateOrderById() {

}
